<CFIF IsDefined("URL.ST")>
    <cfparam name="url.fk" default="">
    <cfparam name="url.id" default="">
    <cfparam name="url.at" default="">
    <cfparam name="url.ab" default="">
    <cfparam name="url.am" default="">

	<cfif Len(url.id) and Len(url.fk)>
    	<cfquery name="chkVal" datasource="#client.company_dsn#">
        	SELECT COUNT(DOCNUMBER) AS COUNT 
            FROM CINNOPAALLOWANCE
            WHERE NOPA_DOCNO_FK = '#url.fk#'
            AND PERSONNELIDNO = '#url.id#'
        </cfquery>
        
        <CFIF chkVal.COUNT>
        	<cfquery name="UPD" datasource="#client.company_dsn#">
            	UPDATE CINNOPAALLOWANCE
                SET 
                	ALLOWANCE_TYPE_FK  = '#url.at#',
                    ALLOWANCE_BASIS_FK = '#url.ab#',  
                    ALLOWANCE_AMOUNT  =  '#NumberFormat(url.am,"99.99")#'
                WHERE 
            		NOPA_DOCNO_FK = '#url.fk#' AND     
					PERSONNELIDNO = '#url.id#'   	
            </cfquery>
        <CFELSE>
        	<cfquery name="INS" datasource="#client.company_dsn#">
            	INSERT INTO CINNOPAALLOWANCE
                	(NOPA_DOCNO_FK,PERSONNELIDNO,ALLOWANCE_TYPE_FK,ALLOWANCE_BASIS_FK,ALLOWANCE_AMOUNT)
                VALUES(
                	'#url.fk#',
                    '#url.id#',
                    '#url.at#',
                    '#url.ab#',
                    '#NumberFormat(url.am,"99.99")#'  
               	)
            </cfquery>
        </CFIF>
	</cfif>  
	<cfreturn>
</CFIF>

<CFIF IsDefined("URL.ajx")>
	<CFSET CTR = ""> 
	<CFIF Len(URL.AJX)>
    	<CFSET CTR = URL.AJX>
    </CFIF>
    
	<CFSET oldNEW_ALLOWANCE = 'oldNEW_ALLOWANCE#CTR#'>
    <CFSET hidNEW_ALLOWANCE ='hidNEW_ALLOWANCE#CTR#'>
    <CFSET edtNEW_ALLOWANCE = 'edtNEW_ALLOWANCE#CTR#'>
    <CFSET lkNEW_ALLOWANCE = 'lkNEW_ALLOWANCE#CTR#'>
    
    <CFSET oldALLOW_BASIS = 'oldALLOW_BASIS#CTR#'>
    <CFSET hidALLOW_BASIS = 'hidALLOW_BASIS#CTR#'>
    <CFSET edtALLOW_BASIS = 'edtALLOW_BASIS#CTR#'>
    <CFSET lkALLOW_BASIS = 'lkALLOW_BASIS#CTR#'>
    
    <CFSET oldALLOW_AMNT = 'oldALLOW_AMNT#CTR#'>
    <CFSET edtALLOW_AMNT = 'edtALLOW_AMNT#CTR#'>
    
    <CFSET ITEMCODE = "">
    <CFSET ITEMDESC = "">
    <CFSET RECURRINGTYPE = "">
    <CFSET RECURRINGTYPEDESC = "">
    <CFSET AMOUNT = "">
	<CFSET hasOpt = TRUE>
    <cfif IsDefined("URL.ITEMCODE") AND LEN(URL.ITEMCODE) >
    	<CFSET hasOpt = FALSE>
    	<CFSET ITEMCODE = URL.ITEMCODE>
        <CFSET ITEMDESC = URL.ITEMDESC>
        <CFSET RECURRINGTYPE = URL.RECURRINGTYPE>
        <CFSET RECURRINGTYPEDESC = URL.RECURRINGTYPEDESC>
        <CFSET AMOUNT = URL.AMOUNT>
    </cfif>
    <CFOUTPUT> 
	[<tr class="a1">
    	<td colspan = 3><div style="border:1px solid ##000;border-bottom:none;">&nbsp;</div></td>
    </tr>
    
    <tr class="a1">
        <td nowrap="" width="150" valign="bottom" class="a" style="border-left:1px solid ##000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Allowance Type:</td>
        <td nowrap="" class="a" valign="bottom">&nbsp;</td>
        <td style="vertical-align:bottom;border-right:1px solid ##000;">
            <input type="hidden" name="#oldNEW_ALLOWANCE#" value="">
            <input type="hidden" name="#hidNEW_ALLOWANCE#" size="15" maxlength="30.0" value="#ITEMCODE#" onblur="GetValue('C','CLKALLOWANCE','#edtNEW_ALLOWANCE#,#hidNEW_ALLOWANCE#',
      'eForm','ALLOWANCECODE~ALLOWANCECODE~ftString,DESCRIPTION~DESCRIPTION~ftString','ALLOWANCECODE','#lkNEW_ALLOWANCE#','DESCRIPTION',',,',',,',this.value)" style="width: 220px;">
      <input type="hidden" name="#edtNEW_ALLOWANCE#" value="#ITEMCODE#">
      <CFIF hasOpt>
      <a href="javascript:ShowLookup('C','CLKALLOWANCE','#edtNEW_ALLOWANCE#,#hidNEW_ALLOWANCE#','eForm','ALLOWANCECODE~ALLOWANCECODE~ftString,DESCRIPTION~DESCRIPTION~ftString','ALLOWANCECODE','#lkNEW_ALLOWANCE#','DESCRIPTION',',,',',,')"></CFIF>
          <img src="http://imachinecloud.com/unDB/images/lookup.gif" border="0" alt="Select from Lookup" align="bottom"></a>&nbsp;
      
            <input readonly="" type="text" name="#lkNEW_ALLOWANCE#" size="35" value="#ITEMDESC#" style="width: 191px;">
        </td>
    </tr>
    
    <tr class="a1">
        <td nowrap="" width="150" valign="bottom" class="a" style="border-left:1px solid ##000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Allowance Basis:</td>
        <td nowrap=""  class="a" valign="bottom">&nbsp;</td>
        <td style="vertical-align:bottom;border-right:1px solid ##000;">
            <input type="hidden" name="#oldALLOW_BASIS#" value="">
            <input type="hidden" name="#hidALLOW_BASIS#" size="15" maxlength="30.0" value="#RECURRINGTYPE#" onblur="GetValue('C','CLKRECURRINGTYPE','#edtALLOW_BASIS#,#hidALLOW_BASIS#',
          'eForm','RECURRINGTYPE~RECURRINGTYPE~ftString,DESCRIPTION~DESCRIPTION~ftString','RECURRINGTYPE','#lkALLOW_BASIS#','DESCRIPTION',',,',',,',this.value)" style="width: 220px;">
          <input type="hidden" name="#edtALLOW_BASIS#" value="#RECURRINGTYPE#">
          <CFIF hasOpt>
          <a href="javascript:ShowLookup('C','CLKRECURRINGTYPE','#edtALLOW_BASIS#,#hidALLOW_BASIS#','eForm','RECURRINGTYPE~RECURRINGTYPE~ftString,DESCRIPTION~DESCRIPTION~ftString','RECURRINGTYPE','#lkALLOW_BASIS#','DESCRIPTION',',,',',,')"></CFIF>
              <img src="http://imachinecloud.com/unDB/images/lookup.gif" border="0" alt="Select from Lookup" align="bottom"></a>&nbsp;
          
            <input readonly="" type="text" name="#lkALLOW_BASIS#" size="35" value="#RECURRINGTYPEDESC#" style="width: 191px;">
        </td>
    </tr>
    
    <tr class="a1">
        <td nowrap="" width="150" valign="bottom" class="a" style="border-left:1px solid ##000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Allowance Amount:</td>
        <td nowrap=""  valign="bottom" class="a">&nbsp;
        </td>
        <td style="vertical-align:bottom;border-right:1px solid ##000;">
            <input type="hidden" name="#oldALLOW_AMNT#" value="">
            <input type="text" name="#edtALLOW_AMNT#" size="15" maxlength="15" value="#AMOUNT#" align="RIGHT" onkeyup="CheckDigit('0123456789.', this); setGross();" ondblclick="GetLastInput(this)" style="width: 218px;" class="a2">
        </td>
    </tr>
    <tr class="a1">
    	<td colspan = 3><div style="border:1px solid ##000;border-top:none;">&nbsp;</div></td>
    </tr>
    <tr class="a1"><td>&nbsp;</td></tr>  
   
    ]</CFOUTPUT>
    <cfreturn>
</CFIF>

<cfinclude template="OriginatorDtls.cfm">
<CFIF IsDefined("URL.QRY")>
	<cfparam name="URL.QRY" default="">
    <cfparam name="URL.DOC" default="">
    <cfprocessingdirective suppresswhitespace="yes">
    <cfsetting showdebugoutput="no">
    <cfcontent type="application/x-javascript">
    
    <cfquery name="getSub" datasource="#client.company_dsn#" maxrows="1">
        SELECT SUBCOMPANYCODE AS DSN
        FROM CMFPA
        WHERE PERSONNELIDNO = '#URL.QRY#'
    </cfquery> 
    <cfset SUBCOMPANY_DSN = getSub.DSN>
	<cfset dbo = '.DBO.'>
    <CFIF uCase(CLIENT.DBMS) EQ 'MYSQL'>
    	<cfset dbo = '.'>
    </CFIF>
    
	<cfquery name="getDtls" datasource="#CLIENT.GLOBAL_DSN#">
    	SELECT 
			A.DATEHIRED,
            B.DESCRIPTION AS EMPLOYEMENTSTATUS,
            C.DESCRIPTION AS POSITION,
            D.DESCRIPTION AS DEPARTMENT,
            E.DESCRIPTION AS PLEVEL,
            F.DESCRIPTION AS PCLASS, 
            G.DESCRIPTION AS CCHARGING,
            H.DESCRIPTION AS DIVSN,
            I.DESCRIPTION AS COMPANY,
            A.MEMO
        FROM #CLIENT.COMPANY_DSN##dbo#CMFPA A 

        LEFT JOIN #CLIENT.COMPANY_DSN##dbo#CLKEMPLOYMNTSTATUS B ON B.EMPLOYMENTSTATUS = A.EMPLOYMENTSTATUS
        LEFT JOIN #CLIENT.COMPANY_DSN##dbo#CLKPOSITION C ON C.POSITIONCODE = A.POSITIONCODE
        LEFT JOIN #CLIENT.COMPANY_DSN##dbo#CLKDEPARTMENT D ON D.DEPARTMENTCODE = A.DEPARTMENTCODE
        LEFT JOIN #CLIENT.COMPANY_DSN##dbo#CLKLEVEL E ON E.CODELEVEL = A.LEVELCODE
        LEFT JOIN #CLIENT.COMPANY_DSN##dbo#CLKJOBGRADE F ON F.JOBGRADECODE = A.JOBGRADECODE
        LEFT JOIN #CLIENT.COMPANY_DSN##dbo#CLKCOSTCENTERS G ON G.COSTCENTERCODE = A.COSTCENTERCODE
        LEFT JOIN #CLIENT.COMPANY_DSN##dbo#CLKDIVISION H ON H.DIVISIONCODE = A.DIVISIONCODE
        LEFT JOIN GLKCOMPANY I ON I.COMPANYCODE = A.COMPANYCODE 
        
        WHERE A.PERSONNELIDNO = '#URL.QRY#'    
    </cfquery>

    <cfquery name="getPay" datasource="#SUBCOMPANY_DSN#">
    	SELECT CURRENTAMOUNT FROM SINCBSALARYCURRENT
        WHERE PERSONNELIDNO = '#URL.QRY#'  
    </cfquery>
    
    <cfset basicPay = 0>
    <CFIF getPay.RecordCount>
    	<cfset basicPay = NumberFormat(getPay.CURRENTAMOUNT,'99.99')>  
    </CFIF>
    

		 <CFIF ucase(CLIENT.DBMS) EQ 'MSSQL'>
         	<CFSET DBO = ".dbo.">
         <cfelse>
         	<CFSET DBO = ".">
         </CFIF>
         
         
         <cfquery name="getAllow" datasource="#CLIENT.COMPANY_DSN#">
            SELECT ITEMCODE,AMOUNT,RECURRINGTYPE
            FROM #SUBCOMPANY_DSN##DBO#SINCBBENEFITSINGLE
            WHERE PERSONNELIDNO = '#URL.QRY#' 
            AND ITEMCODE NOT IN(
            	SELECT ALLOWANCE_TYPE_FK
                FROM CINNOPAALLOWANCE
                WHERE PERSONNELIDNO = '#URL.QRY#'  
                AND NOPA_DOCNO_FK = '#URL.DOC#'
            )
            UNION ALL
            
            SELECT ALLOWANCE_TYPE_FK AS ITEMCODE,ALLOWANCE_AMOUNT AS AMOUNT,ALLOWANCE_BASIS_FK AS RECURRINGTYPE
            FROM CINNOPAALLOWANCE
            WHERE PERSONNELIDNO = '#URL.QRY#'  
            AND NOPA_DOCNO_FK = '#URL.DOC#'
        </cfquery>
	

    
    <cfset allowStr = "">
    <cfset totAllow = "0.00">
    <cfoutput query="getAllow">
    	<CFSET allowCode =  ITEMCODE> 
        <CFSET allowDesc =  ITEMCODE>   
        
		<CFSET allowAmt =  NumberFormat(AMOUNT,'99.99')>  
        
        <CFSET allowRecc =  RECURRINGTYPE> 
        <CFSET allowCode =  RECURRINGTYPE> 
        
        <cfset totAllow = totAllow + AMOUNT>
        
		<cfquery name="getDesc" datasource="#client.company_dsn#">
			SELECT PYITEMDESCRIPTION
            FROM CLKPYITEMS
            WHERE PYITEMCODE = '#ITEMCODE#'
		</cfquery>
        
        <cfif getDesc.RecordCount>
        	<CFSET allowDesc =  getDesc.PYITEMDESCRIPTION> 
        </cfif>
        
        <cfquery name="getDescRec" datasource="#client.company_dsn#">
			SELECT DESCRIPTION
            FROM CLKRECURRINGTYPE
            WHERE RECURRINGTYPE = '#RECURRINGTYPE#'
		</cfquery>
        
        <cfif getDescRec.RecordCount>
        	<CFSET allowRecc =  getDescRec.DESCRIPTION> 
        </cfif>    
        <CFSET allowStr = allowStr & '{"ITEMCODE":"#allowCode#","ITEMDESC":"#allowDesc#","RECURRINGTYPE":"#allowCode#","RECURRINGTYPEDESC":"#allowRecc#","AMOUNT":"#allowAmt#"}'>
        <CFIF CurrentRow neq RecordCount>
        	<CFSET allowStr = allowStr & ','>	    
        </CFIF>  
    </cfoutput>
    <cfif getAllow.RecordCount>
        <cfset totAllow = totAllow + basicPay>
        <cfset totAllow = NumberFormat(totAllow,'99.99')>
    	<cfset allowStr = ',"ALLOWANCE":[' & allowStr & '],"ALLOWANCETOT":['& totAllow &'],"BASICPAY":['& basicPay &']'>
    </cfif>
    
    
    <cfset str = '{"DATA":[{'>
    <CFSET row = 1>
    <cfloop list="#getDtls.ColumnList#" DELIMITERS="," index="column">
    
    	<cfset sval = Evaluate("getDtls.#column#") >
    	<cfif IsDate(sval)>
        	<cfset sval = DateFormat(sval,"MMMM DD, YYYY")>
        <cfelse>
        	<cfset tmp = "">
            <cfset sval = lcase(sval)>
        	<cfloop list="#sval#" delimiters=" " index="dval">
				<cfscript>
                    tmp = tmp & REReplace( dval, "([a-z]{1})", "\U\1", "ONE" ) & ' ';
                </cfscript>
            </cfloop>
            <cfset sval = tmp>
        </cfif>
		<cfset str = str & '"' & column & '":"' & sval & '"'> 
        <cfif row neq ListLen(getDtls.ColumnList,',')> 
            <cfset str = str & ','>
        </cfif>
        <cfset row = row + 1>
    </cfloop>
    <cfset str = str & allowStr>
    <cfset str = str & "}]}">
    
    
	<cfscript> 
		writeOutput(str);
    </cfscript>
    
	</cfprocessingdirective> 
<CFELSE>
	<cfhtmlhead text='<script src="http://code.jquery.com/jquery-1.9.1.js"></script>' />
	<script type="text/javascript">
        var pidHd = '[name="lkEMP_NO"]';
        var pid = '[name="hidEMP_NO"]';
		var pidOld = '[name="oldVal"]';
		var docno = '[name="edtNOPA_NO"]';
		var sve = '[name="Save"]';
		
		
	//	var pname = '[name="EMP_NAME"]';
		var empstat = '[name="EMP_NOlkEMPLOYMENTSTATUS"]';
		var dhired = '[name="EMP_NOlkDATEHIRED"]';
		var all_ctr = '[name="all_ctr"]';
		
		
		
		//Group III
		var new_postitle = '[name="lkNEW_POS_TITLE"]';
		var new_poslvl = '[name="edtNEW_POS_LEVEL"]';
		var new_emp_stat = '[name=lkEMP_STATUS]';
		var  new_paylvl= '[name="lkNEW_PAY_LEVEL"]';
		var  new_payclass= '[name="lkNEW_PAY_CLASS"]';
		var  new_costcharging= '[name="lkCOSTCENTERCODE"]';
		var new_dpttle = '[name="lkNEW_DEPT_SECTION"]';
		var new_rmks = '[name="edtNEW_REMARKS"]';
		var new_company = '[name="lkCOMPANY"]';
		var new_division = '[name="lkDIVISION"]';
		

		
		var old_postitle = '[name="OLD_POS_TITLE"]';
		var old_poslvl = '[name="OLD_POS_LEVEL"]';
		var old_emp_stat = '[name="OLD_EMP_STAT"]';
		var old_payclass = '[name="OLD_PAY_CLASS"]';
		var old_paylvl = '[name="OLD_PAY_LEVEL"]';
		var old_dpttle = '[name="OLD_DEPT"]';
		var old_rmks = '[name="OLD_REMARKS"]';
		var old_costcharging= '[name="OLD_COSTCENTERCODE"]';
		var old_company= '[name="OLD_lkCOMPANY"]';
		var old_division = '[name="old_lkDIVISION"]';

		
		//Group IV
		var  new_bpay = '[name="edtNEW_BASIC_PAY"]';
		var  new_all_type = '[name="lkNEW_ALLOWANCE"]';
		var  new_all_basis = '[name="lkALLOW_BASIS"]';
		var  new_all_amnt = '[name="edtALLOW_AMNT"]';
		var  new_others = '[name="edtNEW_OTHERS"]';
		var  new_gross = '[name="edtNEW_GROSS"]';
		
		var  old_bpay = '[name="old_BASIC_PAY"]';
		var  old_others = '[name="old_OTHERS"]';
		var  old_gross = '[name="old_GROSS"]';
		var new_division = '[name="lkDIVISION"]';
		
		
		
		var xmlhttp;
		var wdt = '220';
		var mrgn = 7;
		

		

        $(document).ready(function() {
          	initVw();
			
			$('#exall').click(function(){
				showLk('');
				loadXMLDoc();
			});
			
			$(new_bpay).keyup(function(){
				setGross();
				
			});
			
			
			$('.add_but').click(function(){ 
				addAllowNo();
			});
			$( '.add_but' ).trigger( "click" );
			
			$(sve).click(function(){
				document.body.style.cursor='wait';
				getAllwnce();
			});
			setInterval(chktext,0.5);	
			
        })
		
		
		function setGross(){
			var a = $(new_bpay).val();	
			a1 = parseFloat(a);
			a1 = (a1 == a) ? a1 : 0;
			b1 = 0;
			ls = document.getElementsByClassName("a2");
			
			for(i=0; i < ls.length; i++){
				b = ls.item(i).value;
				b1 = parseFloat(b);
				b1 = (b1 == b) ? b1 : 0;
				a1 += b1;
			}
				

			$(new_gross).val(a1);
			
		}
		
		function chktext() {
			if ($(pid).val() != $(pidOld).val()) {
				$(pidOld).val($(pid).val());
				loadXMLDoc($(pid).val());

			}
		}
			

		
		function addVws(){
			
			var str_nw_old = '<tr><td nowrap="" width="150" colspan=2>&nbsp</td><td width="220px"><table width="45%" class="b"><tr align="center"><td>Old Data</td><td>New Data</td></tr></table></td></tr>';
			
			var str_allow = '<tr><td nowrap="" width="150" valign="bottom">&nbsp;</td><td nowrap=""  valign="bottom">&nbsp;</td><td style="vertical-align:bottom;width:" class="add_h">&nbsp;</td></tr><tr><td nowrap="" width="150" colspan=2 class="add_but"><a href="##">Additional Allowance</a></td></tr>';
			
			
			$('<input type="hidden" name="oldVal">').insertAfter(pidHd);
			$(str_nw_old).insertBefore($(new_postitle).closest('tr'));
			$(str_nw_old).insertBefore($(new_bpay).closest('tr'));
			$(str_allow).insertBefore($(new_gross).closest('tr'));
			$('<input readonly="" type="hidden" name="all_ctr" value="0">').insertAfter(new_bpay);
			$('<input readonly="" type="text" name="OLD_POS_TITLE">').insertAfter('[name=hidNEW_POS_TITLE]'); 
			$('<input readonly="" type="text" name="OLD_POS_LEVEL">').insertAfter('[name="hidNEW_POS_LEVEL"]');
			$('<input readonly="" type="text" name="OLD_EMP_STAT">').insertAfter('[name="hidEMP_STATUS"]');
			$('<input readonly="" type="text" name="OLD_PAY_LEVEL">').insertAfter('[name="hidNEW_PAY_LEVEL"]');
			$('<input readonly="" type="text" name="OLD_PAY_CLASS">').insertAfter('[name="hidNEW_PAY_CLASS"]');
			$('<input readonly="" type="text" name="OLD_DEPT">').insertAfter('[name="hidNEW_DEPT_SECTION"]'); 
			$('<input readonly="" type="text" name="OLD_COSTCENTERCODE">').insertAfter('[name="hidCOSTCENTERCODE"]'); 
			$('<textarea cols="39" rows="4" name="OLD_REMARKS" style="resize:both;" readonly />').insertBefore(new_rmks); 
			$('<input readonly="" type="text" name="OLD_lkCOMPANY">').insertAfter('[name="hidCOMPANY"]'); 
			$('<input readonly="" type="text" name="old_lkDIVISION">').insertAfter('[name="hidDIVISION"]'); 
			



			$('<input readonly="" type="text" name="old_BASIC_PAY">&nbsp;&nbsp;').insertBefore(new_bpay);
			$('<input readonly="" type="text" name="old_OTHERS">&nbsp;&nbsp;').insertBefore(new_others);
			$('<input readonly="" type="text" name="old_GROSS">&nbsp;&nbsp;').insertBefore(new_gross); 
			 
			
		
		
		
		
		
	
		}
		 
		function initVw(){
			$('[name=hidNEW_POS_TITLE]').attr('type','hidden');
			$('[name=hidNEW_DEPT_SECTION]').attr('type','hidden');
			$('[name=hidNEW_ALLOWANCE]').attr('type','hidden');			
			$('[name=hidEMP_STATUS]').attr('type','hidden');
			$('[name=hidNEW_EMP_STATUS]').attr('type','hidden');
			$('[name=hidALLOW_BASIS]').attr('type','hidden');
			$('[name=hidNEW_PAY_CLASS]').attr('type','hidden');
			$('[name=hidOTHER_NATURE]').attr('type','hidden');
			$('[name=hidSALARY_ADJ]').attr('type','hidden');
			$('[name=hidCOSTCENTERCODE]').attr('type','hidden');
			$('[name=hidCOMPANY]').attr('type','hidden');
			$('[name=hidDIVISION]').attr('type','hidden');
			$('[name=hidNEW_PAY_LEVEL]').attr('type','hidden');
			
			
			addVws();
			$(pidHd).attr('type','hidden');
		
			$('form[name=eForm] input[type=text]').each(function(){
			 	var input = $(this); 
				input.css('width',wdt+'px');
			});
			

			$(old_bpay).css('margin-right',5+'px');
			$(old_gross).css('margin-right',5+'px');	

				
		}
		
		function loadXMLDoc(ix){
			
			dcn =  $(docno).val();

			if (window.XMLHttpRequest)
			  xmlhttp=new XMLHttpRequest();
			else
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			
			xmlhttp.onreadystatechange = function(){
				if (xmlhttp.readyState ==4 && xmlhttp.status ==200){
					setData(xmlhttp.responseText);
				}else{ 
					clearVw();	
				}
			} 
			 
			xmlhttp.open("GET","../pre_activities/nopa.cfm?&qry="+ix+"&doc="+dcn,true); 
			xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
			xmlhttp.send();	
		}
		
		function setData(obj){
			clearVw();
			
			var jdata = JSON.parse(obj);
			jdata = jdata.DATA[0];
			allwnceData = jdata.ALLOWANCE;
			//sname = jdata.FIRSTNAME + ' ' +jdata.MIDDLENAME + ' ' + jdata.LASTNAME;
			
		//	$(pname).val(sname);
			$(empstat).val(jdata.EMPLOYEMENTSTATUS);
			$(dhired).val(jdata.DATEHIRED);
			$(old_postitle).val(jdata.POSITION);
			$(old_dpttle).val(jdata.DEPARTMENT);
			$(old_emp_stat).val(jdata.EMPLOYEMENTSTATUS);
			$(old_payclass).val(jdata.PCLASS);
			$(old_paylvl).val(jdata.PLEVEL);
			$(old_gross).val(jdata.ALLOWANCETOT);	
			$(old_bpay).val(jdata.BASICPAY);	
			$(old_rmks).val(jdata.MEMO);	
			$(old_costcharging).val(jdata.CCHARGING);	
			$(old_division).val(jdata.DIVSN);	
			$(old_company).val(jdata.COMPANY);	
			
			
			
			if(allwnceData.length == 0 ) clearVw();        
			
			
			for(i=0; i< allwnceData.length; i++){   
				ITEMCODE = allwnceData[i].ITEMCODE;
				ITEMDESC = allwnceData[i].ITEMDESC;
				RECURRINGTYPE = allwnceData[i].RECURRINGTYPE;
				RECURRINGTYPEDESC = allwnceData[i].RECURRINGTYPEDESC;
				AMOUNT = allwnceData[i].AMOUNT;
				$(all_ctr).val(i+1); 
				addAllow(ITEMCODE,ITEMDESC,RECURRINGTYPE,RECURRINGTYPEDESC,AMOUNT);
			}
		}
		
		function addAllVw(str1,str2,str3){
			$('<input readonly type="text" class="p" value="'+str1+'">').insertAfter(new_all_type);
			$('<input readonly type="text" class="p" value="'+str2+'">').insertAfter(new_all_basis);
			$('<input readonly type="text" class="p" value="'+str3+'">').insertAfter(new_all_amnt);		
			
 
		}
		
		function clearVw(){
			$(all_ctr).val(0);
			$(".a1").remove();
			addAllowNo();
		}
		
		
		
		
		function addAllowNo(){
			
			var ctr = $(all_ctr).val(); 
			ctr = parseInt(ctr);
			ctr += 1;
			jqajx("../pre_activities/nopa.cfm?ajx="+ctr);
			$(all_ctr).val(ctr);
			
		}
		function addAllow(ITEMCODE,ITEMDESC,RECURRINGTYPE,RECURRINGTYPEDESC,AMOUNT){
			ct = $(all_ctr).val();
			$(".a1").remove();
			URL = "&ITEMCODE="+ITEMCODE+
			"&ITEMDESC="+ITEMDESC+
			"&RECURRINGTYPE="+RECURRINGTYPE+
			"&RECURRINGTYPEDESC="+RECURRINGTYPEDESC+
			"&AMOUNT="+AMOUNT;
			
			jqajx("../pre_activities/nopa.cfm?ajx="+ct+URL);
		}
		
		function jqajx(surl){	
			ct = $(all_ctr).val();
			var response = $.ajax({
				type: "GET",   
				url: surl,   
				async: false,
				success : function(data) {		
				
					 startposition = data.indexOf('[');
					 startposition = parseInt(startposition);
					 endposition   = data.indexOf(']'); 
					 endposition   = parseInt(endposition);	
					 data = data.substring(startposition + 1, endposition);	
					alert(data); 	
					$(data).insertAfter($('.add_h').closest('tr')); 					 
				}
			});	
			
		}
		function getAllwnce(){
			var ctr = $(all_ctr).val(); 
		    dc = $(docno).val();
		    pd = $(pid).val();

			urrs = "fk="+dc+"&id="+pd;
			for(i=1; i<=ctr; i++){
				at = document.getElementsByName('edtNEW_ALLOWANCE'+i).item(0).value;
				ab = document.getElementsByName('edtALLOW_BASIS'+i).item(0).value;
				am = document.getElementsByName('edtALLOW_AMNT'+i).item(0).value;			
				urre = urrs+"&st=&at="+at+"&ab="+ab+"&am="+am;
				jqajxsV(urre);
			}

		}
		function jqajxsV2(urr){	
			var response = $.ajax({
				type: "GET",   
				url: "../pre_activities/nopa.cfm?"+urr,   
				async: false,
				success : function(data) {}    
			});	
			
		} 
		function jqajxsV(urr){
			if (window.XMLHttpRequest)
			  xmlhttp=new XMLHttpRequest();
			else
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			
			xmlhttp.onreadystatechange = function(){
				if (xmlhttp.readyState ==4 && xmlhttp.status ==200){
					return;
				}
			} 
			 
			xmlhttp.open("GET","../pre_activities/nopa.cfm?"+urr,true); 
			xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
			xmlhttp.send();	
		}
    </script>
    <style type="text/css">
	
		.b td{
			font-weight:bold;
			font-size:larger;	
			border-bottom:1px inset #333;
		}
		.b{
			border-collapse:collapse;
			border-spacing:0;	
			margin-bottom:5px;
		}
		
		.p{
			border-color:transparent !important;
			background-color:transparent !important;
			padding:2px;
			width:150px;
			font-weight:bold;
			font-style:italic;	
			margin-left:5px;
			font-size:10px;
		}
	</style>
</CFIF>